﻿<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Pictures" Height="650" Width="780"
        xmlns:WpfApplication1="clr-namespace:WpfApplication1"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
    <Window.Resources>
        <ItemsPanelTemplate x:Key="ItemsPanelTemplate">
            <UniformGrid Columns="{Binding PageCol}" Rows="{Binding PageRow}" HorizontalAlignment="Center"/>
        </ItemsPanelTemplate>

        <DataTemplate x:Key="ItemDataTemplate">
            <StackPanel>
                <Image Source="{Binding Path=ImageSource}" HorizontalAlignment="Center" Width="150" Height="180" Margin="10" Stretch="Fill" />
                <TextBlock Text="{Binding Path=Name}" HorizontalAlignment="Center" Margin="10,0"/>
            </StackPanel>
        </DataTemplate>
        
        <WpfApplication1:IndexToNumConverter x:Key="IndexToNumConverter"></WpfApplication1:IndexToNumConverter>
    </Window.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="auto"></RowDefinition>
        </Grid.RowDefinitions>

        <ListBox ItemsPanel="{DynamicResource ItemsPanelTemplate}" 
                 ItemTemplate="{DynamicResource ItemDataTemplate}"
                 ItemsSource="{Binding PictureDataList}"/>

        <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="right" Margin="10">
            <StackPanel.Resources>
                <Style TargetType="Button">
                    <Setter Property="Height" Value="30"></Setter>
                    <Setter Property="Width" Value="35"></Setter>
                    <Setter Property="BorderThickness" Value="0"></Setter>
                    <Setter Property="Margin" Value="5"></Setter>
                    <Setter Property="FontSize" Value="18"></Setter>
                    <Setter Property="Foreground" Value="YellowGreen"></Setter>
                    <Setter Property="Background" Value="White"></Setter>
                    <Setter Property="FontFamily" Value="Wingdings 3"></Setter>
                </Style>
            </StackPanel.Resources>

            <Button Content="\" ToolTip="Previous page" Command="{Binding PrePageCommand}"></Button>

            <TextBox Name="tbPageNum" VerticalAlignment="Center" Height="27" Margin="5" Width="20"
                     Text="{Binding CurrentPage, Mode=OneWay, Converter={StaticResource IndexToNumConverter}}"/>

            <TextBlock Foreground="YellowGreen" Text="/" VerticalAlignment="Center"/>

            <TextBlock Foreground="YellowGreen" Text="{Binding PageCount}" VerticalAlignment="Center" Margin="5"/>

            <Button Content=";" ToolTip="Go" Command="{Binding GotoPageCommand}" 
                    CommandParameter="{Binding Text,ElementName=tbPageNum}"></Button>

            <Button Content="a" ToolTip="Next page" Command="{Binding NextPageCommand}"></Button>
        </StackPanel>
    </Grid>
</Window>
